﻿<?php 
include 'top1.php';
include '../connect.php';
?>

<div class="ny-right">

  <h3>学生管理</h3>

     <div id="twjs">
<br><br>



<?php
 if ($_GET['action']=='add'){
	
	$query = mysql_query("insert into room (rid,rname) values 
	
	('{$_POST['number']}','{$_POST['name']}')") or die(mysql_error());
		echo "<script type='text/javascript'>alert('添加成功');window.location.href='admin_room.php';</script>";
}
if ($_GET['action']=="del"){
	$query = mysql_query("delete from room where id= ".$_GET['id']);
	echo "<script type='text/javascript'>alert('删除成功');window.location.href='admin_room.php';</script>";
}


?>



<table border=1px cellpadding="0" cellspacing="0" width="670" style="margin:0 auto;">   
<?php 	
echo '<tr><td>学号</td><td>姓名</td><td>密码</td> <td>删除</td></tr>';  
if ($_GET[page]==""){
$_GET[page]=1;}
if (is_numeric($_GET[page])){
$page_size=5;     							
$query="select count(*) as total from room where role like '学生' order by id ";   
$result=mysql_query($query);      					//查询符合条件的记录总条数
$message_count=mysql_result($result,0,"total");		//要显示的总记录数
$page_count=ceil($message_count/$page_size);	  	//根据记录总数除以每页显示的记录数求出所分的页数
$offset=($_GET[page]-1)*$page_size;						//计算下一页从第几条数据开始循环  
$sql=mysql_query("select * from room where role like '学生' order by id limit $offset, $page_size");
$row=mysql_fetch_object($sql);
if(!$row){
echo "<font color='red'>暂无新闻信息!</font>";
}
do{
?>
   
 <tr><td><?php echo $row->id;?> </td><td><?php echo $row->rname;?> </td><td><?php echo $row->rid;?> </td><td><a href="?action=del&id=<?php echo $row->id;?>">删除</a> </td></tr>
            
<?php
}
while($row=mysql_fetch_object($sql));
}
?>	
	     <br>  <br>
                        <tr>
                        <td align="center" colspan="7">
                          <!--  翻页条 -->
							页次：<?php echo $_GET[page];?>/<?php echo $page_count;?>页&nbsp;记录：<?php echo $message_count;?> 条&nbsp; 
							
							<?php
							/*  如果当前页不是首页  */
							if($_GET[page]!=1){
							/*  显示“首页”超链接  */
							echo  "<a href=?page=1>首页</a>&nbsp;";
							/*  显示“上一页”超链接  */
							echo "<a href=?page=".($_GET[page]-1).">上一页</a>&nbsp;";
							}
							/*  如果当前页不是尾页  */
							if($_GET[page]<$page_count){
							/*  显示“下一页”超链接  */
							echo "<a href=?page=".($_GET[page]+1).">下一页</a>&nbsp;";
							/*  显示“尾页”超链接  */
							echo  "<a href=?page=".$page_count.">尾页</a>";
							}
							
							
							mysql_free_result($sql);
							mysql_close($conn);
							?>		
   

</table>
 





 <style  type="text/css">
 table td { padding-left:5px; }
  table td p { width:400px;word-break:break-all ;}
 
 </style>
 
 <br> <br> <br> <br>


<form id="form1" name="form1" method="post" action="?action=add" style=" padding:0 0 0 100px;">
          <table width="600" border="1" align="center">
            
             <tr>
              <td align="right">姓名:</td>
              <td><input name="name" type="text" /></td>
            </tr>
           
              <tr>
              <td align="right">密码:</td>
              <td><input name="number" type="text" /></td>
            </tr>
           
           
           <tr>
              <td colspan="2" align="center"><input type="submit" name="submit" value="添加" /></td>
            </tr>
          </table>
          <p align="center">&nbsp;</p>
		
        </form>
</div>
</div>

<div class="clear"></div>
</div>


<?php 
include 'foot.php';

?>
